﻿using Furion.DependencyInjection;
using Furion.DynamicApiController;
using iemtm.WeChat.Core;
using iemtm.WeChat.Core.Managers;
using Mapster;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace iemtm.WeChat.Application.UserCenter
{
    public class UserAppService : IUserAppService, IDynamicApiController, ITransient
    {
        private readonly IWorkManager _workManager;
        private readonly IUserManager _userManager;
        public UserAppService(IWorkManager workManager, IUserManager userManager)
        {
            _workManager = workManager;
            _userManager = userManager;
        }

        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <returns></returns>
        public ResultModel GetUser()
        {
            ResultModel result = new ResultModel();
            if (_workManager.CurrentUser != null)
            {
                result.Code = 1;
                result.Result = _workManager.CurrentUser;
            }
            else
            {
                result.Code = -1;
                result.Result = "获取用户信息失败";
            }
            return result;
        }
        /// <summary>
        /// 解除微信绑定
        /// </summary>
        /// <returns></returns>

        public async Task<ResultModel> UnWeChatBind()
        {
            ResultModel result = new ResultModel();
            if (_workManager.CurrentUser != null)
            {
                await _userManager.UNBindWeChat(_workManager.CurrentUser.Adapt<UserAccount>());
                result.Code = 1;
                result.Result = _workManager.CurrentUser;
            }
            else
            {
                result.Code = -1;
                result.Result = "获取用户信息失败";
            }
            return result;


        }
  
    }
}
